package com.itheima.stock.controller;


import com.itheima.stock.common.domain.*;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.PageResult;
import com.itheima.stock.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    StockService stockService;

    //获取大盘数据
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerStockMarket(){
        return stockService.getInnerStockMarket();
    }

    //显示国内板块指数
    @GetMapping("/sector/all")
    public R<List<SectorAll>> getSectorAll() {
        return stockService.getSectorAll();
    }

    //查询涨幅榜
    @GetMapping("/stock/increase")
    public R<List<StockIncrease>> getStockIncrease(){
        return stockService.getStockIncrease();
    }

    //涨幅榜分页查询
    @GetMapping("/stock/all")
    public R<PageResult<StockIncrease>> getStockAll(Integer page,Integer pageSize) {
        return stockService.getStockAll(page,pageSize);
    }

    //涨停数据统计查询
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpDownCount(){
        return stockService.getStockUpDownCount();
    }

    /**
     * 涨幅榜数据分页导出到excel
     * @param response 用于响应excel文件
     * @param page 当前页
     * @param pageSize 每页大小
     */
    @GetMapping("/stock/export")
    public void exPort(HttpServletResponse response,Integer page,Integer pageSize){
        stockService.exPort(response,page,pageSize);
    }

    /**
     * 统计国内A股大盘T日和T-1日成交量对比功能（成交量为沪市和深市成交量之和）
     * @return
     */
    @GetMapping("/stock/tradevol")
    public R<Map> getStockTravolCompare(){
        return stockService.stockTradeVol4InnerMarket();
    }

    /**
     * 查询指定时间下股票的涨跌幅度区间统计功能
     * 如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询时间点
     * @return
     */
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.getStockUpDown();
    }

    @GetMapping("/stock/screen/time-sharing")
    public R<List<StockScreenTimeSharing>> stockScreenTimeSharing(String code) {
        return stockService.stockScreenTimeSharing(code);
    }


    /**
     * 单个个股日K数据查询 ，可以根据时间区间查询数日的K线数据
     * 默认查询历史20天的数据；
     * @param code
     * @return
     */
    @GetMapping("stock/screen/dkline")
    public R<List<DayKLinData>> getDayKLinData(String code){
        return stockService.getDayKLinData(code);
    }

}
